﻿using BCCommon;
using BCCommon.Enums;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.HealthReport;
using BCService.TMS.HealthReport;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;


namespace BCTMSRESTful.Controllers.DriverApp.HealthReports
{
    /// <summary>
    /// 健康上报控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "DriverApp")]
    [Route("api/v1/DriverApp/[controller]")]
    public class HealthReportsController : DriverAppBaseController
    {
        private readonly IHealthReportService healthReportService;

        public HealthReportsController(IHealthReportService healthReportService)
        {
            this.healthReportService = healthReportService;
        }

        /// <summary>
        /// 创建一条健康上报信息
        /// </summary>
        /// <param name="healthReportRequestDto">健康上报请求信息</param>
        /// <returns></returns>
        /// <response code="200">健康上报信息提交成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost]
        [Log("创建一条健康上报信息")]
        [ProducesResponseType(typeof(HealthReportDto), 201)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Create([FromBody] HealthReportRequestDto healthReportRequestDto)
        {
            var result = this.healthReportService.Create(healthReportRequestDto, this.Driver.DriverId, null, this.Driver.Name, RoleType.Driver, Driver.CompanyId);
            return this.Created(string.Format("/api/v1/DriverApp/HealthReports/{0}", result.HealthReportId), result);
        }

        /// <summary>
        /// 获取健康上报列表
        /// </summary>
        /// <param name="start">上报时间开始时间</param>
        /// <param name="end">上报时结束时间</param>
        /// <param name="isFever">是否发烧</param>
        /// <param name="isCoughs">是否咳嗽</param>
        /// <param name="ascending">是否正序</param>
        /// <param name="index">页号</param>
        /// <param name="size">每页数据条数</param>
        /// <returns></returns>
        /// <response code="200">健康上报信息查询成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<HealthReportDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult List([FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "is_fever")] bool? isFever,
            [FromQuery(Name = "is_coughs")] bool? isCoughs,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int? index = 1,
            [FromQuery(Name = "size")] int? size = 10)
        {
            return this.Ok(this.healthReportService.GetList(this.Driver.CompanyId, start, end, ascending, index, size, this.Driver.DriverId, RoleType.Driver, isFever, isCoughs));
        }
    }
}
